www.gusucode.com > 智睿政府网站管理系统 V2.1.0 > 智睿政府网站管理系统 V2.1.0\code\manage\Admin_Data.asp

    <!--#include file="../Include/conn.asp"-->
<!--#include file="Admin_check.asp"-->
<%
response.expires = 0 
response.expiresabsolute = now() - 1 
response.addHeader "pragma","no-cache" 
response.addHeader "cache-control","private" 
Response.cachecontrol = "no-cache"
if Instr(session("AdminPurview"),"|119,")=0 then 
  response.write ("<font color='red')>你不具有该管理模块的操作权限,请返回!</font>")
  response.end
end if
'========判断是否具有管理权限 
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>网站后台管理</title>
<LINK href="images/Admin_css.css" type=text/css rel=stylesheet>
<script src="images/admin.js"></script>
</head>

<body>
<table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#6298E1" class="admintable1">
  <tr>
    <td height="25" nowrap background="images/th_bg.gif"><font color="#FFFFFF">&nbsp;<strong>数据库管理</strong></font></td>
  </tr>
  <tr>
    <td height="24" align="center" nowrap  bgcolor="#EBF2F9"><A href="Admin_data.asp?action=SpaceSize" target="mainFrame">空间占用<font color="#0000FF">&nbsp;|&nbsp;</font></A><A href="Admin_data.asp?action=BackupData" target="mainFrame">数据备份</A><a href="Admin_joli.asp" ><font color="#0000FF">&nbsp;</font></a></td>
  </tr>
</table>
<br>
<%
select case request("action")
    case "SpaceSize"
	    SpaceSize()
	case "CompressData"
		if IsSqlDataBase = 1 then
			SQLUserReadme()
		else
			CompressData()
		end if
	case "BackupData"
	    if request("act")="Backup" then
			call updata()
		else
			call BackupData()
		end if
	case "RestoreData"
			if request("act")="Restore" then
				dim Dbpath,backpath,fso
				Dbpath=request.form("Dbpath")
				backpath=request.form("backpath")
				if dbpath="" then
				Call Alert("请输入您要恢复的数据库路径及名称!","-1")	
				else
				Dbpath=server.mappath(Dbpath)
				end if
				backpath=server.mappath(backpath)
			
				Set Fso=Server.CreateObject("Scripting.FileSystemObject")
				if fso.fileexists(dbpath) then  					
					fso.copyfile Dbpath,Backpath
					Call Alert("成功恢复数据!","Admin_data.asp?action=SpaceSize")	
				else
					Call Alert("备份目录下并无您的备份文件!","-1")	
				end if
			else
				call BackupData()
			end if
end select
%>
<%
'====================压缩数据库 =========================
sub BackupData()
%>
<table border="0"  cellspacing="1" cellpadding="5" height="1" align=center width="100%">
				<tr>
  					<th height=25 style="text-align:center;">
  					&nbsp;&nbsp;SQL数据库数据处理说明
  					</th>
  				</tr> 	
 				<tr>
 					<td class="td1"> 			
 			<blockquote>
<B>一、备份数据库</B>
<BR><BR>
1、打开SQL企业管理器,在控制台根目录中依次点开Microsoft SQL Server<BR>
2、SQL Server组-->双击打开你的服务器-->双击打开数据库目录<BR>
3、选择你的数据库名称(如论坛数据库Forum)-->然后点上面菜单中的工具-->选择备份数据库<BR>
4、备份选项选择完全备份,目的中的备份到如果原来有路径和名称则选中名称点删除,然后点添加,如果原来没有路径和名称则直接选择添加,接着指定路径和文件名,指定后点确定返回备份窗口,接着点确定进行备份
<BR><BR>
<B>二、还原数据库</B><BR><BR>
1、打开SQL企业管理器,在控制台根目录中依次点开Microsoft SQL Server<BR>
2、SQL Server组-->双击打开你的服务器-->点图标栏的新建数据库图标,新建数据库的名字自行取<BR>
3、点击新建好的数据库名称(如论坛数据库Forum)-->然后点上面菜单中的工具-->选择恢复数据库<BR>
4、在弹出来的窗口中的还原选项中选择从设备-->点选择设备-->点添加-->然后选择你的备份文件名-->添加后点确定返回,这时候设备栏应该出现您刚才选择的数据库备份文件名,备份号默认为1(如果您对同一个文件做过多次备份,可以点击备份号旁边的查看内容,在复选框中选择最新的一次备份后点确定)-->然后点击上方常规旁边的选项按钮<BR>
5、在出现的窗口中选择在现有数据库上强制还原,以及在恢复完成状态中选择使数据库可以继续运行但无法还原其它事务日志的选项。在窗口的中间部位的将数据库文件还原为这里要按照你SQL的安装进行设置(也可以指定自己的目录),逻辑文件名不需要改动,移至物理文件名要根据你所恢复的机器情况做改动,如您的SQL数据库装在D:\Program Files\Microsoft SQL Server\MSSQL\Data,那么就按照您恢复机器的目录进行相关改动改动,并且最后的文件名最好改成您当前的数据库名(如原来是bbs_data.mdf,现在的数据库是forum,就改成forum_data.mdf),日志和数据文件都要按照这样的方式做相关的改动(日志的文件名是*_log.ldf结尾的),这里的恢复目录您可以自由设置,前提是该目录必须存在(如您可以指定d:\sqldata\bbs_data.mdf或者d:\sqldata\bbs_log.ldf),否则恢复将报错<BR>
6、修改完成后,点击下面的确定进行恢复,这时会出现一个进度条,提示恢复的进度,恢复完成后系统会自动提示成功,如中间提示报错,请记录下相关的错误内容并询问对SQL操作比较熟悉的人员,一般的错误无非是目录错误或者文件名重复或者文件名错误或者空间不够或者数据库正在使用中的错误,数据库正在使用的错误您可以尝试关闭所有关于SQL窗口然后重新打开进行恢复操作,如果还提示正在使用的错误可以将SQL服务停止然后重起看看,至于上述其它的错误一般都能按照错误内容做相应改动后即可恢复<BR><BR>

<B>三、收缩数据库</B><BR><BR>
一般情况下,SQL数据库的收缩并不能很大程度上减小数据库大小,其主要作用是收缩日志大小,应当定期进行此操作以免数据库日志过大<BR>
1、设置数据库模式为简单模式:打开SQL企业管理器,在控制台根目录中依次点开Microsoft SQL Server-->SQL Server组-->双击打开你的服务器-->双击打开数据库目录-->选择你的数据库名称(如论坛数据库Forum)-->然后点击右键选择属性-->选择选项-->在故障还原的模式中选择“简单”,然后按确定保存<BR>
2、在当前数据库上点右键,看所有任务中的收缩数据库,一般里面的默认设置不用调整,直接点确定<BR>
3、<font color=blue>收缩数据库完成后,建议将您的数据库属性重新设置为标准模式,操作方法同第一点,因为日志在一些异常情况下往往是恢复数据库的重要依据</font>
<BR><BR>

<B>四、设定每日自动备份数据库</B><BR><BR>
<font color=red>强烈建议有条件的用户进行此操作!</font><BR>
1、打开企业管理器,在控制台根目录中依次点开Microsoft SQL Server-->SQL Server组-->双击打开你的服务器<BR>
2、然后点上面菜单中的工具-->选择数据库维护计划器<BR>
3、下一步选择要进行自动备份的数据-->下一步更新数据优化信息,这里一般不用做选择-->下一步检查数据完整性,也一般不选择<BR>
4、下一步指定数据库维护计划,默认的是1周备份一次,点击更改选择每天备份后点确定<BR>
5、下一步指定备份的磁盘目录,选择指定目录,如您可以在D盘新建一个目录如:d:\databak,然后在这里选择使用此目录,如果您的数据库比较多最好选择为每个数据库建立子目录,然后选择删除早于多少天前的备份,一般设定4-7天,这看您的具体备份要求,备份文件扩展名一般都是bak就用默认的<BR>
6、下一步指定事务日志备份计划,看您的需要做选择-->下一步要生成的报表,一般不做选择-->下一步维护计划历史记录,最好用默认的选项-->下一步完成<BR>
7、完成后系统很可能会提示Sql Server Agent服务未启动,先点确定完成计划设定,然后找到桌面最右边状态栏中的SQL绿色图标,双击点开,在服务中选择Sql Server Agent,然后点击运行箭头,选上下方的当启动OS时自动启动服务<BR>
8、这个时候数据库计划已经成功的运行了,他将按照您上面的设置进行自动备份
<BR><BR>
修改计划:<BR>
1、打开企业管理器,在控制台根目录中依次点开Microsoft SQL Server-->SQL Server组-->双击打开你的服务器-->管理-->数据库维护计划-->打开后可看到你设定的计划,可以进行修改或者删除操作
<BR><BR>
<B>五、数据的转移(新建数据库或转移服务器)</B><BR><BR>
一般情况下,最好使用备份和还原操作来进行转移数据,在特殊情况下,可以用导入导出的方式进行转移,这里介绍的就是导入导出方式,导入导出方式转移数据一个作用就是可以在收缩数据库无效的情况下用来减小(收缩)数据库的大小,本操作默认为您对SQL的操作有一定的了解,如果对其中的部分操作不理解,可以咨询动网相关人员或者查询网上资料<BR>
1、将原数据库的所有表、存储过程导出成一个SQL文件,导出的时候注意在选项中选择编写索引脚本和编写主键、外键、默认值和检查约束脚本选项<BR>
2、新建数据库,对新建数据库执行第一步中所建立的SQL文件<BR>
3、用SQL的导入导出方式,对新数据库导入原数据库中的所有表内容<BR>
 			</blockquote> 	
 					</td>
 				</tr>
 			</table>
<%
end sub
sub SpaceSize()
%>
<table width="99%" height="1" border="0" align="center" cellpadding="3"  cellspacing="1" bgcolor="#F2F9E8" class="admintable1">
  <tr>
    <td height="25" colspan="2" background="images/skin/th_bg.gif" class="admintitle">程序占用空间情况 </td>
  </tr>
  <tr>
    <td width="19%" height="30" align="center" bgcolor="#EBF2F9">系统占用空间总计:</td>
    <td width="81%" bgcolor="#EBF2F9"><img src="images/bar1.gif" width=400 height=9 />&nbsp;
    <%allsize()%></td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#EBF2F9">数据库占用空间:</td>
    <td bgcolor="#EBF2F9"><img src="images/bar1.gif" width=<%=drawbar("DataBase")%> height=9 />&nbsp;
    <%othersize("DataBase")%></td>
  <tr>
    <td height="30" align="center" bgcolor="#EBF2F9">系统后台占用空间:</td>
    <td bgcolor="#EBF2F9"><img src="images/bar1.gif" width=<%=drawbar("weblogin")%> height=9 />&nbsp;
    <%othersize("weblogin")%></td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#EBF2F9">备份数据占用空间:</td>
    <td bgcolor="#EBF2F9"><img src="images/bar1.gif" width=<%=drawbar("DataBase/bak")%> height=9 />&nbsp;
    <%othersize("DataBase/bak")%></td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#EBF2F9">系统城市占用空间:</td>
    <td bgcolor="#EBF2F9"><img src="images/bar1.gif" width=<%=drawbar("images")%> height=9 />&nbsp;
    <%othersize("images")%></td>
  </tr>
    <tr>
    <td height="30" align="center" bgcolor="#EBF2F9">编辑器占用空间:</td>
    <td bgcolor="#EBF2F9"><img src="images/bar1.gif" width=<%=drawbar("Zhirui")%> height=9 />&nbsp;
    <%othersize("Zhirui")%></td>
  </tr>
    <tr>
    <td height="30" align="center" bgcolor="#EBF2F9">函数库占用空间:</td>
    <td bgcolor="#EBF2F9"><img src="images/bar1.gif" width=<%=drawbar("Include")%> height=9 />&nbsp;
    <%othersize("Include")%></td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#EBF2F9">上传目录占用空间:</td>
    <td bgcolor="#EBF2F9"><img src="images/bar1.gif" width=<%=drawbar("Upload")%> height=9 />&nbsp;
    <%othersize("Upload")%></td>
  </tr>
</table>
<%end sub%>
<%
sub othersize(names)
	dim fso,path,ml,mlsize,dx,d,size
	set fso=Server.CreateObject("Scripting.FileSystemObject")
	path=server.mappath("..\Images")
	ml=left(path,(instrrev(path,"\")-1))&"\"&names
	
	On Error Resume Next
	set d=fso.getfolder(ml) 
	If Err Then
		err.Clear
		Response.Write "<font color=red>提示:没有“"&names&"”目录</font>"					
		'Response.End()
	End If
	mlsize=d.size
	size=mlsize
	dx=size & "&nbsp;Byte" 
	if size>1024 then
	   size=(Size/1024)
	   dx=formatnumber(size,2) & "&nbsp;KB"
	end if
	if size>1024 then
	   size=(size/1024)
	   dx=formatnumber(size,2) & "&nbsp;MB"		
	end if
	if size>1024 then
	   size=(size/1024)
	   dx=formatnumber(size,2) & "&nbsp;GB"	   
	end if   
	response.write dx
end sub

sub allsize()
	dim fso,path,ml,mlsize,dx,d,size
	set fso=Server.CreateObject("Scripting.FileSystemObject")
	path=server.mappath("../index.asp")
	ml=left(path,(instrrev(path,"\")-1))
	set d=fso.getfolder(ml) 
	mlsize=d.size
	size=mlsize
	dx=size & "&nbsp;Byte" 
	if size>1024 then
	   size=(Size/1024)
	   dx=size & "&nbsp;KB"
	end if
	if size>1024 then
	   size=(size/1024)
	   dx=formatnumber(size,2) & "&nbsp;MB"		
	end if
	if size>1024 then
	   size=(size/1024)
	   dx=formatnumber(size,2) & "&nbsp;GB"	   
	end if   
	response.write dx
end sub

Function Drawbar(drvpath)
	dim fso,drvpathroot,d,size,totalsize,barsize
	set fso=Server.CreateObject("Scripting.FileSystemObject")
	drvpathroot=server.mappath("../Images")
	drvpathroot=left(drvpathroot,(instrrev(drvpathroot,"\")-1))
	set d=fso.getfolder(drvpathroot)
	totalsize=d.size
	
	On Error Resume Next
	drvpath=server.mappath("../"&drvpath)
	If Err Then
		err.Clear
		Response.Write "没有名为“"&drvpath&"”的目录,您可以修改文件以正确显示该目录的使用量。"			
		Response.End()
	End If
	set d=fso.getfolder(drvpath)
	size=d.size
	
	barsize=cint((size/totalsize)*400)
	Drawbar=barsize
End Function 

Function FileList(FolderUrl,FileExName)
Set fso=Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set folder=fso.GetFolder(Server.MapPath(Trim(FolderUrl)))
Set file=folder.Files
FileList=""
For Each FileName in file
If Trim(FileExName)<>"" Then
	If InStr(Trim(FileExName),Trim(Mid(FileName.Name,InStr(FileName.Name,".")+1,len(FileName.Name))))>0 Then
    	FileList=FileList&""&FileName.Name&"|"
	End If
Else
     FileList=FileList&"<a href='#'>"&FileName.Name&"</a><br>"
End If
Next
Set file=Nothing
Set folder=Nothing
Set fso=Nothing
End Function
%>
</body>
</html>